import jdk.internal.org.objectweb.asm.tree.MultiANewArrayInsnNode;

import java.io.File;
import java.util.Scanner;

public class IO1 {

    public static Scanner scan=new Scanner(System.in);
    public static void main(String[] args) {

        System.out.println("请输入路径");
        String basepath=scan.next();
        File root=new File(basepath);
        if(!root.isDirectory())
        {
            System.out.println("输入有误");
            return;
        }
        System.out.println("请输入你想删除的文件");
        String target=scan.next();
        find(root,target);

    }
    public static void find(File root,String target) {
        //System.out.println(root.getAbsolutePath());
        File[] files = root.listFiles();
        if (files == null) {
            return;
        }
        for (File file : files) {

            if (file.isDirectory()) {
                find(file, target);
            } else {
                if (file.getName().contains(target)) {
                    System.out.println("请确认是否要删除:删除请按yes,取消删除请按No");
                    String user = scan.next();
                    if (user.equals("yes")) {
                        file.delete();
                        System.out.println("删除成功");

                    } else {
                        System.out.println("取消删除");

                    }


                }
            }
        }
    }
}
